﻿using MediatR;
using SlaughterItem.Common.Domains.UPCTable;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace SlaughterItem.API.Application.Commands.Week02.UPC
{
    //获取商品分类数据
    public class GetUPCTypeDataHandler : IRequestHandler<GetUPCTypeDataCommand, Result>
    {
        public GetUPCTypeDataHandler(IBaseRepository<UPCTypeData> uPCTypeDataRepository)
        {
            UPCTypeDataRepository = uPCTypeDataRepository;
        }

        public IBaseRepository<UPCTypeData> UPCTypeDataRepository { get; set; }
        public async Task<Result> Handle(GetUPCTypeDataCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Search };
            var list = UPCTypeDataRepository.GetAll().ToList();
            if (list != null)
            {
                result.Data = list;
                result.Code = (int)CommonErrorCode.Success;
                return result;
            }
            else
            {
                return result;
            }
        }
    }
}
